#include <cstddef>
#include <iostream>
#include <limits>
// #include <format>
#include <source_location>

using namespace std;


// g++12.x 无法正常运行 使用vs2022 即可正常运行

int main()
{
	size_t integerCount{numeric_limits<size_t>::max()};
	// cout << format("Trying to allocate memory for {} integers.", integerCount) << endl;
	cout << "Trying to allocate memory for " << integerCount << " integers." << endl;

	int *ptr{new (nothrow) int[integerCount]};
	if (ptr == nullptr)
	{
		auto location{source_location::current()};
		// cerr << format("{}({}): Unable to allocate memory!",
		// 							 location.file_name(), location.line())
		// 		 << endl;
		cerr << location.file_name() << "(" << location.line() << "): Unable to allocate memory! " << endl;

		// Handle memory allocation failure.
		return 1;
	}
	// Proceed with function that assumes memory has been allocated.
}
